package com.ruoyi.study.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.study.domain.StyRedis;
import com.ruoyi.study.service.IStyRedisService;
import com.ruoyi.study.service.IStyRedisStudyService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * redis信息Controller
 * 
 * @author dwb
 * @date 2024-09-04
 */
@RestController
@RequestMapping("/redis")
public class StyRedisController extends BaseController
{
    @Resource
    private IStyRedisService styRedisService;

    @Resource
    private IStyRedisStudyService styRedisStudyService;


    /**
     * 查询redis信息列表
     */
    @RequiresPermissions("study:redis:list")
    @GetMapping("/list")
    public TableDataInfo list(StyRedis styRedis)
    {
        startPage();
        List<StyRedis> list = styRedisService.selectStyRedisList(styRedis);
        return getDataTable(list);
    }


    /**
     * 导出redis信息列表
     */
    @RequiresPermissions("study:redis:export")
    @Log(title = "redis信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StyRedis styRedis)
    {
        List<StyRedis> list = styRedisService.selectStyRedisList(styRedis);
        ExcelUtil<StyRedis> util = new ExcelUtil<StyRedis>(StyRedis.class);
        util.exportExcel(response, list, "redis信息数据");
    }

    /**
     * 获取redis信息详细信息
     */
    @RequiresPermissions("study:redis:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(styRedisService.selectStyRedisById(id));
    }

    /**
     * 新增redis信息
     */
    @RequiresPermissions("study:redis:add")
    @Log(title = "redis信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StyRedis styRedis)
    {
        return toAjax(styRedisService.insertStyRedis(styRedis));
    }

    /**
     * 修改redis信息
     */
    @RequiresPermissions("study:redis:edit")
    @Log(title = "redis信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StyRedis styRedis)
    {
        return toAjax(styRedisService.updateStyRedis(styRedis));
    }

    /**
     * 删除redis信息
     */
    @RequiresPermissions("study:redis:remove")
    @Log(title = "redis信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(styRedisService.deleteStyRedisByIds(ids));
    }
}
